using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AutomaticDoorController:MonoBehaviour {

	[SerializeField] float timeBeforeChange = 0.25f;

	Door door;
	float time;
	int detectTime;
	bool wantOpen;
	public int lockedByLocker;

	void Start() {
		door=GetComponent<Door>();
	}

	private void Update() {
		time+=Time.deltaTime;
	}

	private void FixedUpdate() {
		detectTime--;
		wantOpen=detectTime>0;

		if(lockedByLocker<=0) {
			if(time>=timeBeforeChange&&wantOpen==door.isClose) door.SwitchState();
		} else {
			if(!door.isClose) door.SwitchState();
			lockedByLocker--;
		}
	}

	void OnTriggerStay2D(Collider2D other) {
		Mob otherMob = other.GetComponent<Mob>();
		if(otherMob!=null) detectTime=5;

	}
}
